package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.TencentGoodsInfoDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.TencentGoodsInfo;

/**
 * 
 * @description 腾讯产品DAO
 * @author Wangxuegang
 * @date 2012-9-17
 * 
 */
@Repository("tencentGoodsInfoDAO")
public class TencentGoodsInfoDAOImpl extends SuperDAO<TencentGoodsInfo>
		implements TencentGoodsInfoDAO {

	/**
	 * 分页查询
	 * 
	 * @param tencentGoodsInfo
	 * @return
	 */
	@Override
	public Pagination<TencentGoodsInfo> queryPaginationList(
			TencentGoodsInfo tencentGoodsInfo) {
		Pagination<TencentGoodsInfo> paginationList = null;
		Integer rowCount = queryRowCount(tencentGoodsInfo);

		tencentGoodsInfo.calculate();
		List<TencentGoodsInfo> list = queryResultList(tencentGoodsInfo);
		paginationList = this.queryPagination(rowCount, list, tencentGoodsInfo);

		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(TencentGoodsInfo tencentGoodsInfo) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.TencentGoodsInfoMapper.queryRowCount",
				tencentGoodsInfo);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param
	 * @return
	 */
	private List<TencentGoodsInfo> queryResultList(
			TencentGoodsInfo tencentGoodsInfo) {
		List<TencentGoodsInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.TencentGoodsInfoMapper.queryResultList",
				tencentGoodsInfo);
		return list;
	}

	/**
	 * 查询记录<br>
	 */
	@Override
	public TencentGoodsInfo queryGoodsInfoGoodsId(String goodsId) {
		TencentGoodsInfo tencentGoodsInfo = null;
		tencentGoodsInfo = this.getSqlSession().selectOne(
				"mybatis.xml.TencentGoodsInfoMapper.queryGoodsInfo", goodsId);

		return tencentGoodsInfo;
	}

	/**
	 * 产品审核,修改记录
	 */
	@Override
	public void saveAuditGoods(TencentGoodsInfo tencentGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.TencentGoodsInfoMapper.saveAuditGoods",
				tencentGoodsInfo);
	}

	@Override
	public void insert(TencentGoodsInfo tencentGoodsInfo) {
		this.getSqlSession().insert(
				"mybatis.xml.TencentGoodsInfoMapper.insert", tencentGoodsInfo);
	}

	@Override
	public TencentGoodsInfo queryGoodsByName(String productName) {
		TencentGoodsInfo tencentGoodsInfo = this.getSqlSession().selectOne(
				"mybatis.xml.TencentGoodsInfoMapper.queryGoodsInfoByName",
				productName);
		return tencentGoodsInfo;
	}

	@Override
	public String queryMaxGoodsId() {
		String id = this.getSqlSession().selectOne(
				"mybatis.xml.TencentGoodsInfoMapper.queryMaxGoodsId");
		return id;
	}

	@Override
	public List<TencentGoodsInfo> queryAllGoodsInfo() {
		List<TencentGoodsInfo> list = this.getSqlSession().selectList(
				"mybatis.xml.TencentGoodsInfoMapper.queryAllGoodsInfo");
		return list;
	}

	@Override
	public void updateState(TencentGoodsInfo tencentGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.TencentGoodsInfoMapper.updateState",
				tencentGoodsInfo);
	}

	@Override
	public void update(TencentGoodsInfo tencentGoodsInfo) {
		this.getSqlSession().update(
				"mybatis.xml.TencentGoodsInfoMapper.updateGoods",
				tencentGoodsInfo);
	}

}
